<?php

namespace My\Controller;

use Utuo\BackgroundController;

class MicroVoteCommentController extends BackgroundController {
	private $micro_vote_id;
	private $status = array (
			'0' => '未审核',
			'1' => '已通过',
			'2' => '未通过' 
	);
	public function _initialize() {
		$this->micro_vote_id = I ( 'micro_vote_id', 0, 'intval' );
		$this->setControllerTitle ( "评论管理" );
		$this->setActionTitle ( array (
				'index' => '评论列表',
				'recycle' => '回收站' 
		), null, array (
				'micro_vote_id' => $this->micro_vote_id 
		) );
		$this->setActionNav ( array (
				'index',
				'recycle' 
		) );
	}
	public function getLists($is_deleted) {
		$condation = array (
				'cid' => $this->aid,
				'micro_vote_id' => $this->micro_vote_id,
				'is_deleted' => $is_deleted 
		);
		$microVoteComment = M ( 'MicroVoteComment' )->where ( $condation )->page ( $this->getPage (), $this->getPageSize () )->order('id desc')->select ();
		foreach ( $microVoteComment as &$v ) {
			$v ['statusOptions'] = \Utuo\Form::getOption ( $this->status, $v ['status'] );
		}
		$count = D ( 'MicroVoteComment' )->where ( $condation )->count ();
		$this->showPage ( $count, $this->getPageSize () );
		
		$this->assign ( 'microVoteComment', $microVoteComment )->display ();
	}
	public function setStatusAction() {
		$id = I ( "id", 0, "intval" );
		$status = I ( "status", 0, "intval" );
		$d = D ( "MicroVoteComment" );
		if ($d->where ( "id={$id}" )->setField ( "status", $status )) {
			$this->ajaxSuccess ();
		} else {
			$this->ajaxError ( $d->getError () );
		}
	}
}